package cn.mw.cmdb.enums;

import cn.hutool.json.JSONArray;
import cn.mw.components.mongodb.exception.BusinessException;
import com.alibaba.fastjson.JSONObject;

public enum AlgorithmAvailableEnum {

    ICMP_STATUS("icmp状态", "ICMP_PING"),
    AGENT_PING_STATUS("agent状态", "AGENT_PING_STATUS"),
    DB_STATUS("数据库状态", "MW_DB_STATUS"),
    HOST_AVAILABLE("主机可用性", "MW_HOST_AVAILABLE");

    private final String chineseName;
    private final String englishName;

    private static final String KEY = "available";

    AlgorithmAvailableEnum(String chineseName, String englishName) {
        this.chineseName = chineseName;
        this.englishName = englishName;
    }

    public String getChineseName() {
        return chineseName;
    }

    public String getEnglishName() {
        return englishName;
    }

    public static JSONObject getAll() {
        JSONObject object = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        for (AlgorithmAvailableEnum value : AlgorithmAvailableEnum.values()) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("chineseName", value.getChineseName());
            jsonObject.put("englishName", value.getEnglishName());
            jsonArray.add(jsonObject);
        }
        object.put(KEY, jsonArray);
        return object;
    }

    public static AlgorithmAvailableEnum getAlgorithmAvailableByEName(String ename) {
        for (AlgorithmAvailableEnum value : AlgorithmAvailableEnum.values()) {
            if (ename.equals(value.getEnglishName())) {
                return value;
            }
        }
        throw new BusinessException("");
    }
}
